package it.eng.area118.mdocommon.android.network;

import it.eng.area118.mdocommon.Network;
import it.eng.area118.mdocommon.android.log.BasicLogger;
import it.eng.area118.mdocommon.android.util.AndroidApplicationContext;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;

public class ConnectionChangeReceiver extends BroadcastReceiver {

	@Override
	public void onReceive(Context context, Intent intent) {
		try {
			Network network = (Network) AndroidApplicationContext.getInstance()
					.getApplicationContextValue(Network.NETWORK_SERVICE);
			BasicLogger.writeLog(Network.NETWORK_SERVICE, "onReceive");

			ConnectivityManager connectivityManager = (ConnectivityManager) context
					.getSystemService(Context.CONNECTIVITY_SERVICE);

			network.updateNetworkData(NetworkUtils
					.createNetworkData(connectivityManager));
		} catch (Exception e) {
			BasicLogger.writeLog("ConnectionChangeReceiver",
					"Error while executing onReceive()", e);
		}

	}

}
